package Hot100.Stack;

import java.util.Deque;
import java.util.LinkedList;
import java.util.Stack;

public class dailyTemperatures {
    public static void main(String[] args) {
        int[] temperatures = {30,40,50,60};
        int[] result = new dailyTemperatures().dailyTemperatures(temperatures);
        for(int temp : result){
            System.out.print(temp + "  ");
        }
    }
    public int[] dailyTemperatures(int[] temperatures) {
        int lens=temperatures.length;
        int []res=new int[lens];
        Deque<Integer> stack=new LinkedList<>();
        for(int i=0;i<lens;i++){

            while(!stack.isEmpty()&&temperatures[i]>temperatures[stack.peek()]){
                res[stack.peek()]=i-stack.peek();
                stack.pop();
            }
            stack.push(i);
        }

        return  res;
    }
}
